class Element {
  constructor (params) {
    this.tagName = params.tag
    this.attrs = params.attrs || {}
    this.children = params.children || []
  }
  append (params) {
    const el = new Element(params)
    this.children.push(el)
  }
  render () {
    const el = document.createElement(this.tagName)
    for (let [name, value] of Object.entries(this.attrs)) {
      el.setAttribute(name, value)
    }
    this.children.forEach(child => {
      const isElement = child instanceof Element
      const childNode = isElement ? child.render() : document.createTextNode(child)
      el.appendChild(childNode)
    })
    return el
  }
}
